﻿using System;
using ExFlash.Records;

namespace ExFlash.Tags
{
    public class DefineMorphShape2Tag : DefineMorphShapeTag
    {
        public RectangleRecord StartEdgeBounds
        {
            get;
            protected set;
        }

        public RectangleRecord EndEdgeBounds
        {
            get;
            protected set;
        }

        public Boolean UsesNonScalingStrokes
        {
            get;
            protected set;
        }

        public Boolean UsesScalingStrokes
        {
            get;
            protected set;
        }

        public DefineMorphShape2Tag(int len, int offset)
            : this(TagCodes.DefineMorphShape2, len, offset)
        {

        }

        protected DefineMorphShape2Tag(TagCodes code, int len, int offset)
            : base(code, len, offset)
        {

        }
        
        public override void SwfDeserialize(BinaryBitReader reader)
        {
            CharacterId = reader.ReadUInt16();

            StartBounds = new RectangleRecord();
            StartBounds.SwfDeserialize(reader);

            EndBounds = new RectangleRecord();
            EndBounds.SwfDeserialize(reader);

            StartEdgeBounds = new RectangleRecord();
            StartEdgeBounds.SwfDeserialize(reader);

            EndEdgeBounds = new RectangleRecord();
            EndEdgeBounds.SwfDeserialize(reader);

            reader.SkipBits(6);
            UsesNonScalingStrokes = reader.ReadBoolean();
            UsesScalingStrokes = reader.ReadBoolean();

            reader.AlignBits();

            Offset = reader.ReadUInt32();

            MorphFillStyles = new MorphFillStyleArray();
            MorphFillStyles.SwfDeserialize(reader);

            MorphLineStyles = new MorphLineStyleArray(TagCode);
            MorphLineStyles.SwfDeserialize(reader);

            StartEdges = new Shape(ShapeType.Shape2);
            StartEdges.SwfDeserialize(reader);

            EndEdges = new Shape(ShapeType.Shape2);
            EndEdges.SwfDeserialize(reader);
        }
    }
}
